<template>
	<view class="container">
		<!-- 顶部用户信息区域 -->
		<view class="user-header" @click="handleHeaderClick">
			<view class="avatar-container">
				<image :src="userInfo.head" class="avatar"></image>
			</view>
			<view class="user-info">
				<text class="username">{{ userInfo.nickname }}</text>
				<text class="edit-info">{{userInfo.user_sign||'编辑个人信息更完美哦！'}}</text>
			</view>
		</view>

		<!-- 四个主要功能按钮 -->
		<view class="function-buttons">
			<navigator url="/pages/my/wallet" hover-class="none">
				<view class="button-item">
					<view class="icon-container">
						<image src="/static/androidImg/icon_wallet.png" class="icon"></image>
					</view>
					<text class="button-text">我的钱包</text>
				</view>
			</navigator>
			<navigator url="/pages/coupon/couponList" hover-class="none">
				<view class="button-item">
					<view class="icon-container">
						<image src="/static/androidImg/icon_discount.png" class="icon"></image>
					</view>
					<text class="button-text">优惠券</text>
				</view>
			</navigator>
			<navigator url="/pages/my/noticeList" hover-class="none">
				<view class="button-item">
					<view class="icon-container">
						<image src="/static/androidImg/icon_notice.png" class="icon"></image>
					</view>
					<text class="button-text">通知</text>
				</view>
			</navigator>
			<navigator url="/pages/my/collect" hover-class="none">
				<view class="button-item">
					<view class="icon-container">
						<image src="/static/androidImg/icon_collection.png" class="icon"></image>
					</view>
					<text class="button-text">我的收藏</text>
				</view>
			</navigator>
		</view>

		<!-- 功能列表 -->
		<view class="function-list">
			<navigator url="/pages/my/consumptionRecord" hover-class="none">
				<view class="list-item">
					<text class="item-text">消费记录</text>
					<view class="arrow-icon iconfont icon-arrow-right"></view>
				</view>
			</navigator>
			<view class="list-item" @click="callPhone">
				<text class="item-text">联系客服</text>
				<view class="arrow-icon iconfont icon-arrow-right"></view>
			</view>
			<navigator url="/pages/setting/feedback" hover-class="none">
				<view class="list-item">
					<text class="item-text">意见反馈</text>
					<view class="arrow-icon iconfont icon-arrow-right"></view>
				</view>
			</navigator>
			<navigator url="/pages/setting/about" hover-class="none">
				<view class="list-item">
					<text class="item-text">关于我们</text>
					<view class="arrow-icon iconfont icon-arrow-right"></view>
				</view>
			</navigator>
			<navigator url="/pages/setting/setting" hover-class="none">
				<view class="list-item">
					<text class="item-text">设置</text>
					<view class="arrow-icon iconfont icon-arrow-right"></view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '../../api/request.js';
	export default {
		data() {
			return {
				userInfo: {
					nickname: '未登录',
					head: '/static/androidImg/login_head.png',
					user_sign: ''
				}
			}
		},
		onLoad() {
			// 调用接口获取用户信息
			// this.getUserInfo();
		},
		onShow() {
			if (!uni.getStorageSync('token')) {
				uni.redirectTo({
					url: '/pages/register/login'
				})
				return;
			}
			this.getUserInfo();
		},
		methods: {
			handleHeaderClick() {
				const token = uni.getStorageSync('token');
				if (token) {
					uni.navigateTo({
						url: '/pages/setting/info'
					});
				} else {
					uni.navigateTo({
						url: '/pages/register/login'
					});
				}
			},
			getUserInfo() {
				getUserInfo().then(res => {
					if (res.code === 1 && res.data) {
						// 更新用户信息
						this.userInfo = {
							nickname: res.data.nickname || '未设置昵称',
							head: res.data.head || '/static/androidImg/login_head.png',
							user_sign: res.data.user_sign || '编辑个人信息更完美哦'
						};
					}
				}).catch(err => {
					console.error('获取用户信息失败:', err);
				});
			},
			// 拨打客服电话
			callPhone() {
				const config = uni.getStorageSync('config');
				uni.makePhoneCall({
					phoneNumber: config.service_phone
				});
			}
		}
	}
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		background-color: #f5f5f5;
		display: flex;
		flex-direction: column;
	}

	/* 顶部用户信息区域 */
	.user-header {
		background: linear-gradient(135deg, #FE0000, #fe3c2b);
		color: white;
		padding: 40rpx 30rpx;
		display: flex;
		align-items: center;
	}

	.avatar-container {
		width: 160rpx;
		height: 160rpx;
		border-radius: 50%;
		background-color: rgba(255, 255, 255, 0.2);
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 30rpx;
	}

	.avatar {
		width: 140rpx;
		height: 140rpx;
		border-radius: 50%;
	}

	.user-info {
		flex: 1;
	}

	.username {
		display: block;
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.edit-info {
		display: block;
		font-size: 24rpx;
		opacity: 0.8;
	}

	/* 四个主要功能按钮 */
	.function-buttons {
		background-color: white;
		padding: 30rpx 0;
		display: flex;
		justify-content: space-around;
		margin-bottom: 20rpx;
	}

	.button-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.icon-container {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 15rpx;
	}

	.icon {
		width: 80rpx;
		height: 80rpx;
	}

	.button-text {
		font-size: 28rpx;
		color: #333;
	}

	/* 功能列表 */
	.function-list {
		background-color: white;
		margin-bottom: 20rpx;
	}

	.list-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}

	.item-text {
		font-size: 32rpx;
		color: #333;
	}

	.arrow-icon {
		width: 20rpx;
		height: 36rpx;
		background-size: contain;
		background-repeat: no-repeat;
		background-position: center;
	}

	/* 底部导航栏 */
	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 120rpx;
		background-color: white;
		display: flex;
		justify-content: space-around;
		align-items: center;
		border-top: 1rpx solid #f0f0f0;
	}

	.tab-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.tab-icon {
		width: 50rpx;
		height: 50rpx;
		margin-bottom: 10rpx;
	}

	.tab-text {
		font-size: 24rpx;
		color: #999;
	}

	.tab-item.active .tab-text {
		color: #ff6b6b;
	}
</style>